package com.imooc.scala.course06

import org.apache.avro.ipc.specific.Person

import scala.util.Random

object MatchApp {
  def main(args: Array[String]): Unit = {
    val names = Array("Akiho Yoshizawa","YuiHatana","Aoi Sola")
    val name = names(Random.nextInt(names.length))

    name match {
      case "Akiho Yoshizawa" => println("吉老师...")
      case "YuiHatana" => println("波老师...")
      case _ => println("真不知道你们在说什么啊 ， 我很纯洁啊")
    }


//    judgeGrade("B")
//    def judgeGrade(grade:String): Unit ={
//      grade match {
//        case "A" => println("Excellent...")
//        case "B" => println("good...")
//        case "C" => println("just so so...")
//        case _ => println("fighting...")
//      }
//    }


    def judgeGrade(name:String,grade:String): Unit ={
      grade match {
        case "A" => println("Excellent...")
        case "B" => println("good...")
        case "C" => println("just so so...")
        case _ if(name =="lisi") => println(name + ", you are a good boy...")
        case _ => println("You need work harder...")
      }
    }
    judgeGrade("zhangsan","D")
    judgeGrade("lisi","D") // 双重过滤

//
//    def greeting(array: Array[String]): Unit ={
//      array match{
//        case Array("zhangsan") => println(" Hi zhangsan")
//        case Array(x,y) => println("Hi:" +x + "," + "y")
//        case Array("zhangsan",_*) =>println("Hi:zhangsan and your friends")
//        case _ => println("Hi:everybody...")
//      }
//    }
//    greeting(Array("lisi","zhangsan","wangwu"))
//

//    def greeting(list:List[String]): Unit ={
//      list match{
//        case "zhangsan"::Nil => println(" Hi zhangsan")
//        case x::y => println("Hi:" +x + "," + "y")
//        case "zhangsan"::tail =>println("Hi:zhangsan and your friends")
//        case _ => println("Hi:everybody...")
//      }
//    }
//    greeting(List("zhangsan"))


//    def matchType(obj:Any): Unit ={
//      obj match{
//        case x:Int => println("Int")
//        case s:String => println("String")
//        case m:Map[_,_] => m.foreach(println)
//        case _ => println("other type")
//      }
//    }
//    matchType(1)

    def caseclassMatch(person: Person): Unit ={
      person match {
        case CTO(name,floor) => println("CTO , Floor")
        case Employee(name,floor) => println("EM,floor")
        case _ => println("other")
      }
    }
    caseclassMatch(CTO("tom","22"))
    class Person
    case class CTO(name: String,floor: String) extends Person
    case class Employee(name: String,floor: String) extends Person
    case class Other(name: String ) extends Person

  }
}
